class Role < ActiveRecord::Base
	#has_many :users, :through => :roles, :source => :user
	has_many :users, :class_name => "User", :finder_sql =>
      'SELECT DISTINCT u.* ' +
      'FROM users u, roles_users ru ' +
      'WHERE ru.role_id = #{id} AND ru.user_id = u.id ' +
      'ORDER BY u.name'
	
	ADMIN = 'admin'
	MODERATOR = 'moderator'
	DEFAULT = 'default'
	
	def self.find_all
		find(:all, :conditions=>"ident <> 'admin'", :order=>"name")
	end
	
	def self.detect(ident=DEFAULT)
		find_by_ident(ident)
	end
end
